#-----------------------------------------------------------------------------* # # @file gtl_instruction_parser.galgas # # @section desc File description # # Parsing of GTL. # # @section copyright Copyright # # Goil OIL compiler, part of Trampoline RTOS # # Trampoline is copyright (c) CNRS, University of Nantes, # Ecole Centrale de Nantes # Trampoline is protected by the French intellectual property law. # # This software is distributed under the GNU Public Licence V2. # Check the LICENSE file in the root directory of Trampoline # # $Date$ # $Rev$ # $Author$ # $URL$ # #-----------------------------------------------------------------------------* syntax gtl_instruction_parser (gtl_scanner) { rule !@gtlExpression expression rule !@gtlVarPath path rule !@gtlVarPath variable !@bool hereInstead #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $let$ let @location where = .here ?let @gtlVarPath variable select $:=$ ?let @gtlExpression expression instruction = @gtlLetInstruction.new { !where !signature(!where) !variable !expression } or $+=$ ?let @gtlExpression expression instruction = @gtlLetAddInstruction.new { !where !signature(!where) !variable !expression } or $-=$ ?let @gtlExpression expression instruction = @gtlLetSubstractInstruction.new { !where !signature(!where) !variable !expression } or $*=$ ?let @gtlExpression expression instruction = @gtlLetMultiplyInstruction.new { !where !signature(!where) !variable !expression } or $/=$ ?let @gtlExpression expression instruction = @gtlLetDivideInstruction.new { !where !signature(!where) !variable !expression } or $mod=$ ?let @gtlExpression expression instruction = @gtlLetModuloInstruction.new { !where !signature(!where) !variable !expression } or $<<=$ ?let @gtlExpression expression instruction = @gtlLetShiftLeftInstruction.new { !where !signature(!where) !variable !expression } or $>>=$ ?let @gtlExpression expression instruction = @gtlLetShiftRightInstruction.new { !where !signature(!where) !variable !expression } or $&=$ ?let @gtlExpression expression instruction = @gtlLetAndInstruction.new { !where !signature(!where) !variable !expression } or $|=$ ?let @gtlExpression expression instruction = @gtlLetOrInstruction.new { !where !signature(!where) !variable !expression } or $^=$ ?let @gtlExpression expression instruction = @gtlLetXorInstruction.new { !where !signature(!where) !variable !expression } or instruction = @gtlLetUnconstructedInstruction.new { !where !signature(!where) !variable } end } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $unlet$ let @location where = .here ?let @gtlVarPath variable instruction = @gtlUnletInstruction.new { !where !signature(!where) !variable } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $error$ let @location where = .here ?let @gtlVarPath variable ?let @bool hereInstead $:$ ?let @gtlExpression expression instruction = @gtlErrorStatementInstruction.new { !where !signature(!where) !variable !hereInstead !expression } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $warning$ let @location where = .here ?let @gtlVarPath variable ?let @bool hereInstead $:$ ?let @gtlExpression expression instruction = @gtlWarningStatementInstruction.new { !where !signature(!where) !variable !hereInstead !expression } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $print$ let @location where = .here ?let @gtlExpression expression instruction = @gtlPrintStatementInstruction.new { !where !signature(!where) !false !expression } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $println$ let @location where = .here select ?let @gtlExpression expression instruction = @gtlPrintStatementInstruction.new { !where !signature(!where) !true !expression } or instruction = @gtlPrintStatementInstruction.new { !where !signature(!where) !true !@gtlTerminal.new { !where !@gtlString.new { !where !emptylstring() !"" } } } end } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $display$ let @location where = .here ?let @gtlVarPath variable instruction = @gtlDisplayStatementInstruction.new { !where !signature(!where) !variable } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $sort$ let @location where = .here ?let @gtlVarPath variable select @sortingKeyList sortList = .emptyList $by$ repeat $identifier$ ?let @lstring key ?let @lsint order sortList += !key !order while $,$ end instruction = @gtlSortStatementStructInstruction.new { !where !signature(!where) !variable !sortList } or ?let @lsint order instruction = @gtlSortStatementInstruction.new { !where !signature(!where) !variable !order } end } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $tab$ let @location where = .here ?let @gtlExpression expression instruction = @gtlTabStatementInstruction.new { !where !signature(!where) !expression } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $variables$ let @location where = .here instruction = @gtlVariablesInstruction.new { !where !signature(!where) !false } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $libraries$ let @location where = .here instruction = @gtlLibrariesInstruction.new { !where !signature(!where) } } #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { $[!$ ?let @gtlVarPath target $identifier$ ?let @lstring setterName let @location where = .here @gtlExpressionList argumentList = .emptyList select or $:$ repeat ?let @gtlExpression argument argumentList += !argument while $,$ end end $]$ instruction = @gtlSetterCallInstruction.new { !where !signature(!where) !target !setterName !argumentList } } #-----------------------------------------------------------------------------* rule !@lsint order { select $>$ order = @lsint. new { !-1 !@location.here} or $<$ order = @lsint. new { !1 !@location.here} end } #-----------------------------------------------------------------------------* rule ?@gtlContext context ?!@library lib { $import$ $string$ ?let @lstring fileName @string fullName = [fileName string] if [fullName pathExtension] != "gtm" then fullName = [fileName string] + ".gtm" end @bool found = false if not [fullName fileExists] then # search in path for (searchPath) in [context importPath] do if not found then let @string name = [searchPath stringByAppendingPath !fullName] if [name fileExists] then fullName = name found = true end end end else found = true end if found then if not [lib hasImport !fullName] then [!?lib doImport !fullName] grammar gtl_module_grammar in @lstring.new{ !fullName ![fileName location] } !context !?lib end else error .here : "module not found" end } }