2 Copyright (C) 1997-2017 JDERobot Developers Team 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Library General Public License for more details. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. 17 Authors : Okan Asik (asik.okan@gmail.com) 32 while funcExists
and len(funcStr) > 0
and funcStr.index(
'{') >= 0:
33 funcStr = funcStr.strip()
34 funcStartIndex = funcStr.index(
'{')
35 funcSignature = funcStr[0:funcStartIndex].strip()
36 returnType = funcSignature[0:funcSignature.index(
' ')].strip()
37 returnTypes.append(returnType)
38 funcName = funcSignature[funcSignature.index(
' '):].strip()
39 funcNames.append(funcName)
41 firstCurlyFound =
False 42 firstCurlyIndex =
None 44 for i, ch
in enumerate(funcStr):
47 if not firstCurlyFound:
48 firstCurlyFound =
True 53 if curlyCounter == 0
and firstCurlyFound:
59 codes.append(funcStr[firstCurlyIndex:lastCurlyIndex+1])
63 funcStr = funcStr[lastCurlyIndex+1:].strip()
64 if len(funcStr) > 0
and funcStr.index(
'{') >= 0:
70 return returnTypes, funcNames, codes
78 variableStr = variableStr.strip()
79 variableLines = variableStr.split(
';')
80 for varLine
in variableLines:
81 varLine = varLine.strip()
85 varType = varLine[0:varLine.find(
' ')]
88 if varLine.find(
'=') >= 0:
90 varName = varLine[varLine.find(
' ')+1:varLine.find(
'=')].strip()
91 initialValue = varLine[varLine.find(
'=')+1:].strip()
93 varName = varLine[varLine.find(
' ')+1:].strip()
96 varNames.append(varName)
97 initialValues.append(initialValue)
99 return types, varNames, initialValues
102 if __name__ ==
'__main__':
104 void myFunction(int a) { 127 for (int i = 0; i < 10; i++) { 140 sampleVariables =
''' 141 int a = 12; int b = 23; 142 float myVar; float myVar2 = 12.2; 145 types, varNames, initialValues = CPPParser.parseVariables(sampleVariables)
146 for i
in range(len(types)):
149 print(initialValues[i])
def parseVariables(variableStr)
def parseFunctions(funcStr)