From 37cb5fedceeeed202214cf8784a804714ceec885 Mon Sep 17 00:00:00 2001 From: Anders Nilsson <anders.nilsson@cs.lth.se> Date: Thu, 9 Nov 2006 10:43:50 +0100 Subject: [PATCH] Generate Parser.java. VERY hard-coded for now --- .bzrignore | 1 + CompilerGeneration.jrag | 43 +++++ GenCompiler.java | 26 +-- Parser.java | 12 +- siaras/Siaras.ast | 41 ----- siaras/Siaras.jjt | 364 ---------------------------------------- 6 files changed, 60 insertions(+), 427 deletions(-) delete mode 100644 siaras/Siaras.ast delete mode 100644 siaras/Siaras.jjt diff --git a/.bzrignore b/.bzrignore index f67683a..3e5a0ec 100644 --- a/.bzrignore +++ b/.bzrignore @@ -5,3 +5,4 @@ AST semantic.cache plugins testontologies/ontologyV06_Jambalaya.properties +siaras/Parser.java diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag index df7594a..c1fa8bb 100644 --- a/CompilerGeneration.jrag +++ b/CompilerGeneration.jrag @@ -149,3 +149,46 @@ aspect JavaCCGen { pStream.println("}"); } } + +aspect ParserGen { + public void Start.genParser(PrintStream pStream) { + pStream.println("import java.io.FileNotFoundException;"); + pStream.println("import java.io.FileReader;"); + pStream.println("import java.io.InputStreamReader;"); + pStream.println("import java.io.Reader;"); + pStream.println(""); + pStream.println("import AST.SiarasParser;"); + pStream.println("import AST.ParseException;"); + pStream.println("import AST.Start;"); + pStream.println(""); + pStream.println("public class Parser {"); + pStream.println(); + pStream.println(" protected static Start parse(String args[]) {"); + pStream.println(" Reader r = getReader(args);"); + pStream.println(" Start ast = null;"); + pStream.println(" try {"); + pStream.println(" SiarasParser parser = new SiarasParser(r);"); + pStream.println(); + pStream.println(" ast = parser.Start();"); + pStream.println(" } catch (ParseException e) {"); + pStream.println(" System.out.println(e.getMessage());"); + pStream.println(" }"); + pStream.println(" return ast;"); + pStream.println(" }"); + pStream.println(); + pStream.println(" private static Reader getReader(String[] args) {"); + pStream.println(" Reader r = null;"); + pStream.println(" if (args.length != 1) {"); + pStream.println(" r = new InputStreamReader(System.in);"); + pStream.println(" } else {"); + pStream.println(" try {"); + pStream.println(" r = new FileReader(args[0]);"); + pStream.println(" } catch (FileNotFoundException e1) {"); + pStream.println(" System.err.println(\"Dumper: file \" + args[0] + \" not found\");"); + pStream.println(" }"); + pStream.println(" }"); + pStream.println(" return r;"); + pStream.println(" }"); + pStream.println("}"); + } +} diff --git a/GenCompiler.java b/GenCompiler.java index 513ebdc..b6ef248 100644 --- a/GenCompiler.java +++ b/GenCompiler.java @@ -16,19 +16,23 @@ public class GenCompiler extends Parser { if (!siarasDir.isDirectory()) { siarasDir.mkdir(); } - - try { - PrintStream absGrammarStream = new PrintStream(new File("siaras/Siaras.ast")); - ast.genAbsGrammar(absGrammarStream); - } catch (java.io.FileNotFoundException e) { - System.out.println("Could not create file for generated abstract grammar"); - e.printStackTrace(); - } + + String fileName = null; try { - PrintStream javaCCStream = new PrintStream(new File("siaras/Siaras.jjt")); - ast.genJavaCC(javaCCStream); + // Generate JastAdd abstract grammar + fileName = "siaras/Siaras.ast"; + PrintStream pStream = new PrintStream(new File(fileName)); + ast.genAbsGrammar(pStream); + // Generate JavaCC configuration + fileName = "siaras/Siaras.jjt"; + pStream = new PrintStream(new File(fileName)); + ast.genJavaCC(pStream); + // Generate Parser.java + fileName = "siaras/Parser.java"; + pStream = new PrintStream(new File(fileName)); + ast.genParser(pStream); } catch (java.io.FileNotFoundException e) { - System.out.println("Could not create file for generated JavaCC grammar"); + System.out.println("Could not create file: "+fileName); e.printStackTrace(); } } diff --git a/Parser.java b/Parser.java index 2ded572..2ab9a35 100644 --- a/Parser.java +++ b/Parser.java @@ -1,8 +1,3 @@ -/* - * Created on 2005-mar-10 - * - */ -// package programs; import java.io.FileNotFoundException; import java.io.FileReader; @@ -13,10 +8,6 @@ import AST.OwlParser; import AST.ParseException; import AST.Start; -/** - * @author gorel - * - */ public class Parser { protected static Start parse(String args[]) { @@ -25,7 +16,6 @@ public class Parser { try { OwlParser parser = new OwlParser(r); - // Start parsing from the nonterminal "Start". ast = parser.Start(); } catch (ParseException e) { System.out.println(e.getMessage()); @@ -47,4 +37,4 @@ public class Parser { return r; } -} \ No newline at end of file +} diff --git a/siaras/Siaras.ast b/siaras/Siaras.ast deleted file mode 100644 index d58faa3..0000000 --- a/siaras/Siaras.ast +++ /dev/null @@ -1,41 +0,0 @@ -Start ::= Device*; -abstract Thing ::=; -Displace : Move ::=; -Turn : Move ::=; -Move : ManipulationAndHandlingFunction ::=; -MagnetGripper : Gripper ::=; -Orient : Move ::=; -ParallelGripper : PincerGripper ::=; -Arrange : Move ::=; -Feed : Move ::=; -Gripper : ManipulationAndHandling ::=; -StorePartlyOrdered : Store ::=; -ManipulationAndHandlingFunction : MainFunction ::=; -Manufacturing : Device ::=; -Store : ManipulationAndHandlingFunction ::=; -Task : Thing ::=; -MainFunction : Skill ::=; -JointFingerGripper : FingerGripper ::=; -LineParallelGripper : ParallelGripper ::=; -Pass : Move ::=; -Pan : Move ::=; -PincerGripper : Gripper ::=; -ID : Property ::=; -CircularParallelGripper : ParallelGripper ::=; -Assembly : Device ::=; -StoreUnOrdered : Store ::=; -AdditionalFunction : Skill ::=; -Convey : Move ::=; -Device : Thing ::= property:Property* skill:Skill* mainFunction:MainFunction; -FingerGripper : Gripper ::=; -StoreInOrder : Store ::=; -GeneralParallelGripper : ParallelGripper ::=; -Property : Thing ::=; -AngleGripper : PincerGripper ::=; -ManipulationAndHandling : Device ::=; -VacuumGripper : Gripper ::=; -Cost : Property ::=; -IntelligentRobot : Thing ::=; -ElasticFingerGripper : FingerGripper ::=; -Position : Move ::=; -Skill : Thing ::= device:Device*; diff --git a/siaras/Siaras.jjt b/siaras/Siaras.jjt deleted file mode 100644 index 0c47f93..0000000 --- a/siaras/Siaras.jjt +++ /dev/null @@ -1,364 +0,0 @@ -options { - MULTI = true; - VISITOR = true; - NODE_DEFAULT_VOID = true; - NODE_SCOPE_HOOK = false; - NODE_PREFIX = ""; - JAVA_UNICODE_ESCAPE = true; - STATIC = false; -} - -PARSER_BEGIN(SiarasParser) - package AST; - public class SiarasParser { -} -PARSER_END(SiarasParser) - -//----------------------------------------------// -// LEXICAL TOKENS // -//----------------------------------------------// -<DEFAULT, BOUNDS> SKIP : /* WHITE SPACE */ -{ - " " - | - "\t" - | - "\n" - | - "\r" - | - "\f" -}// WHITE SPACE - -SPECIAL_TOKEN : /* COMMENTS */ -{ - < "<!--" ( ~["-"] | ( "-" ~["-"] ) )* "-->"> - | < "<rdfs:comment" ( ~["<"] | ( "<" ~["/"] ) )* "</rdfs:comment>" > -}// COMMENTS - - -<DEFAULT, BOUNDS> TOKEN : /* RESERVED WORDS */ -{ - <XML : "xml" > - |<DISPLACE : "Displace"> - |<TURN : "Turn"> - |<MOVE : "Move"> - |<MAGNETGRIPPER : "MagnetGripper"> - |<ORIENT : "Orient"> - |<PARALLELGRIPPER : "ParallelGripper"> - |<ARRANGE : "Arrange"> - |<FEED : "Feed"> - |<GRIPPER : "Gripper"> - |<STOREPARTLYORDERED : "StorePartlyOrdered"> - |<MANIPULATIONANDHANDLINGFUNCTION : "ManipulationAndHandlingFunction"> - |<MANUFACTURING : "Manufacturing"> - |<STORE : "Store"> - |<TASK : "Task"> - |<MAINFUNCTION : "MainFunction"> - |<JOINTFINGERGRIPPER : "JointFingerGripper"> - |<LINEPARALLELGRIPPER : "LineParallelGripper"> - |<PASS : "Pass"> - |<PAN : "Pan"> - |<PINCERGRIPPER : "PincerGripper"> - |<ID : "ID"> - |<CIRCULARPARALLELGRIPPER : "CircularParallelGripper"> - |<ASSEMBLY : "Assembly"> - |<STOREUNORDERED : "StoreUnOrdered"> - |<ADDITIONALFUNCTION : "AdditionalFunction"> - |<CONVEY : "Convey"> - |<DEVICE : "Device"> - |<FINGERGRIPPER : "FingerGripper"> - |<STOREINORDER : "StoreInOrder"> - |<GENERALPARALLELGRIPPER : "GeneralParallelGripper"> - |<PROPERTY : "Property"> - |<ANGLEGRIPPER : "AngleGripper"> - |<MANIPULATIONANDHANDLING : "ManipulationAndHandling"> - |<VACUUMGRIPPER : "VacuumGripper"> - |<COST : "Cost"> - |<INTELLIGENTROBOT : "IntelligentRobot"> - |<ELASTICFINGERGRIPPER : "ElasticFingerGripper"> - |<POSITION : "Position"> - |<SKILL : "Skill"> -} - - -<DEFAULT, BOUNDS> TOKEN : /* LITERALS */ -{ - < INTEGER_LITERAL: - <DECIMAL_LITERAL> (["l","L"])? - | - <HEX_LITERAL> (["l","L"])? - | - <OCTAL_LITERAL> (["l","L"])? - > - | - < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > - | - < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > - | - < #OCTAL_LITERAL: "0" (["0"-"7"])* > - | - < FLOAT_LITERAL: - (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])? - | - "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? - | - (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? - | - (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"] - > - | - < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > - | - < CHARACTER_LITERAL: - "'" - ( (~["'","\\","\n","\r"]) - | - ("\\" - ( ["n","t","b","r","f","\\","'","\""] - | - ["0"-"7"] ( ["0"-"7"] )? - | - ["0"-"3"] ["0"-"7"] ["0"-"7"] - ) - ) - ) - "'" - > - | - < STRING_LITERAL: - "\"" - ( (~["\"","\\","\n","\r"]) - | - ("\\" - ( ["n","t","b","r","f","\\","'","\""] - | - ["0"-"7"] ( ["0"-"7"] )? - | - ["0"-"3"] ["0"-"7"] ["0"-"7"] - ) - ) - )* - "\"" - > -}// LITERALS - -<DEFAULT, BOUNDS> TOKEN : /* IDENTIFIERS */ -{ - < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|"-")* > - | - < #LETTER: - [ - "\u0024", - "\u0041"-"\u005a", - "\u005f", - "\u0061"-"\u007a", - "\u00c0"-"\u00d6", - "\u00d8"-"\u00f6", - "\u00f8"-"\u00ff", - "\u0100"-"\u1fff", - "\u3040"-"\u318f", - "\u3300"-"\u337f", - "\u3400"-"\u3d2d", - "\u4e00"-"\u9fff", - "\uf900"-"\ufaff" - ] - > - | - < #DIGIT: - [ - "\u0030"-"\u0039", - "\u0660"-"\u0669", - "\u06f0"-"\u06f9", - "\u0966"-"\u096f", - "\u09e6"-"\u09ef", - "\u0a66"-"\u0a6f", - "\u0ae6"-"\u0aef", - "\u0b66"-"\u0b6f", - "\u0be7"-"\u0bef", - "\u0c66"-"\u0c6f", - "\u0ce6"-"\u0cef", - "\u0d66"-"\u0d6f", - "\u0e50"-"\u0e59", - "\u0ed0"-"\u0ed9", - "\u1040"-"\u1049" - ] - > -}// IDENTIFIERS - -<DEFAULT,BOUNDS> TOKEN : /* SEPARATORS */ -{ - < LBRACE : "{" > - | < RBRACE : "}" > - | < LBRACKET : "[" > - | < RBRACKET : "]" > - | < SEMICOLON : ";" > -}// SEPARATORS - -<DEFAULT,BOUNDS> TOKEN : /* OPERATORS */ -{ - < ASSIGN : "=" > -}// OPERATORS - -Start Start() #Start : {} -{ - (Device())* - { return jjtThis; } -} - -void Displace() : {} -{ - <DISPLACE> ">"(Property())* (Skill())* MainFunction() #Displace(0) -} -void Turn() : {} -{ - <TURN> ">"(Property())* (Skill())* MainFunction() #Turn(0) -} -void Move() : {} -{ - <MOVE> ">"(Property())* (Skill())* MainFunction() #Move(0) -} -void MagnetGripper() : {} -{ - <MAGNETGRIPPER> ">"(Property())* (Skill())* MainFunction() #MagnetGripper(0) -} -void Orient() : {} -{ - <ORIENT> ">"(Property())* (Skill())* MainFunction() #Orient(0) -} -void ParallelGripper() : {} -{ - <PARALLELGRIPPER> ">"(Property())* (Skill())* MainFunction() #ParallelGripper(0) -} -void Arrange() : {} -{ - <ARRANGE> ">"(Property())* (Skill())* MainFunction() #Arrange(0) -} -void Feed() : {} -{ - <FEED> ">"(Property())* (Skill())* MainFunction() #Feed(0) -} -void Gripper() : {} -{ - <GRIPPER> ">"(Property())* (Skill())* MainFunction() #Gripper(0) -} -void StorePartlyOrdered() : {} -{ - <STOREPARTLYORDERED> ">"(Property())* (Skill())* MainFunction() #StorePartlyOrdered(0) -} -void ManipulationAndHandlingFunction() : {} -{ - <MANIPULATIONANDHANDLINGFUNCTION> ">"(Property())* (Skill())* MainFunction() #ManipulationAndHandlingFunction(0) -} -void Manufacturing() : {} -{ - <MANUFACTURING> ">"(Property())* (Skill())* MainFunction() #Manufacturing(0) -} -void Store() : {} -{ - <STORE> ">"(Property())* (Skill())* MainFunction() #Store(0) -} -void Task() : {} -{ - <TASK> ">"(Property())* (Skill())* MainFunction() #Task(0) -} -void MainFunction() : {} -{ - <MAINFUNCTION> ">"(Property())* (Skill())* MainFunction() #MainFunction(0) -} -void JointFingerGripper() : {} -{ - <JOINTFINGERGRIPPER> ">"(Property())* (Skill())* MainFunction() #JointFingerGripper(0) -} -void LineParallelGripper() : {} -{ - <LINEPARALLELGRIPPER> ">"(Property())* (Skill())* MainFunction() #LineParallelGripper(0) -} -void Pass() : {} -{ - <PASS> ">"(Property())* (Skill())* MainFunction() #Pass(0) -} -void Pan() : {} -{ - <PAN> ">"(Property())* (Skill())* MainFunction() #Pan(0) -} -void PincerGripper() : {} -{ - <PINCERGRIPPER> ">"(Property())* (Skill())* MainFunction() #PincerGripper(0) -} -void ID() : {} -{ - <ID> ">"(Property())* (Skill())* MainFunction() #ID(0) -} -void CircularParallelGripper() : {} -{ - <CIRCULARPARALLELGRIPPER> ">"(Property())* (Skill())* MainFunction() #CircularParallelGripper(0) -} -void Assembly() : {} -{ - <ASSEMBLY> ">"(Property())* (Skill())* MainFunction() #Assembly(0) -} -void StoreUnOrdered() : {} -{ - <STOREUNORDERED> ">"(Property())* (Skill())* MainFunction() #StoreUnOrdered(0) -} -void AdditionalFunction() : {} -{ - <ADDITIONALFUNCTION> ">"(Property())* (Skill())* MainFunction() #AdditionalFunction(0) -} -void Convey() : {} -{ - <CONVEY> ">"(Property())* (Skill())* MainFunction() #Convey(0) -} -void Device() : {} -{ -"<" <DEVICE> ">"(Property())* (Skill())* MainFunction() #Device(3) -} -void FingerGripper() : {} -{ - <FINGERGRIPPER> ">"(Property())* (Skill())* MainFunction() #FingerGripper(0) -} -void StoreInOrder() : {} -{ - <STOREINORDER> ">"(Property())* (Skill())* MainFunction() #StoreInOrder(0) -} -void GeneralParallelGripper() : {} -{ - <GENERALPARALLELGRIPPER> ">"(Property())* (Skill())* MainFunction() #GeneralParallelGripper(0) -} -void Property() : {} -{ - <PROPERTY> ">"(Property())* (Skill())* MainFunction() #Property(0) -} -void AngleGripper() : {} -{ - <ANGLEGRIPPER> ">"(Property())* (Skill())* MainFunction() #AngleGripper(0) -} -void ManipulationAndHandling() : {} -{ - <MANIPULATIONANDHANDLING> ">"(Property())* (Skill())* MainFunction() #ManipulationAndHandling(0) -} -void VacuumGripper() : {} -{ - <VACUUMGRIPPER> ">"(Property())* (Skill())* MainFunction() #VacuumGripper(0) -} -void Cost() : {} -{ - <COST> ">"(Property())* (Skill())* MainFunction() #Cost(0) -} -void IntelligentRobot() : {} -{ - <INTELLIGENTROBOT> ">"(Property())* (Skill())* MainFunction() #IntelligentRobot(0) -} -void ElasticFingerGripper() : {} -{ - <ELASTICFINGERGRIPPER> ">"(Property())* (Skill())* MainFunction() #ElasticFingerGripper(0) -} -void Position() : {} -{ - <POSITION> ">"(Property())* (Skill())* MainFunction() #Position(0) -} -void Skill() : {} -{ - <SKILL> ">"(Property())* (Skill())* MainFunction() #Skill(1) -} -- GitLab