renamed root parser class to Crystal
This commit is contained in:
parent
31aa9c8768
commit
af1df1a104
@ -1,7 +1,7 @@
|
|||||||
require 'parslet'
|
require 'parslet'
|
||||||
|
|
||||||
require "elf/object_writer"
|
require "elf/object_writer"
|
||||||
require 'parser/composed'
|
require 'parser/crystal'
|
||||||
require 'parser/transform'
|
require 'parser/transform'
|
||||||
require "vm/context"
|
require "vm/context"
|
||||||
require "vm/machine"
|
require "vm/machine"
|
||||||
|
@ -7,7 +7,7 @@ module Parser
|
|||||||
# obviously a work in progress !!
|
# obviously a work in progress !!
|
||||||
# We "compose" the parser from bits, divide and hopefully conquer
|
# We "compose" the parser from bits, divide and hopefully conquer
|
||||||
|
|
||||||
class Composed < Parslet::Parser
|
class Crystal < Parslet::Parser
|
||||||
include BasicTypes
|
include BasicTypes
|
||||||
include Tokens
|
include Tokens
|
||||||
include Keywords
|
include Keywords
|
||||||
@ -19,9 +19,9 @@ module Parser
|
|||||||
|
|
||||||
rule(:argument_list) {
|
rule(:argument_list) {
|
||||||
left_parenthesis >>
|
left_parenthesis >>
|
||||||
( (simple_expression.as(:argument) >>
|
( (simple_expression.as(:argument) >> space? >>
|
||||||
(comma >> simple_expression.as(:argument)).repeat(0)).repeat(0,1)).as(:argument_list) >>
|
(comma >> space? >> simple_expression.as(:argument)).repeat(0)).repeat(0,1)).as(:argument_list) >>
|
||||||
right_parenthesis
|
space? >> right_parenthesis
|
||||||
}
|
}
|
||||||
|
|
||||||
rule(:function_call) { name.as(:function_call) >> argument_list }
|
rule(:function_call) { name.as(:function_call) >> argument_list }
|
||||||
@ -54,6 +54,6 @@ module Parser
|
|||||||
((name.as(:parmeter) >> (comma >> name.as(:parmeter)).repeat(0)).repeat(0,1)).as(:parmeter_list) >>
|
((name.as(:parmeter) >> (comma >> name.as(:parmeter)).repeat(0)).repeat(0,1)).as(:parmeter_list) >>
|
||||||
right_parenthesis
|
right_parenthesis
|
||||||
}
|
}
|
||||||
rule(:root){ function_definition | expression | assignment }
|
rule(:root){ function_definition | expression | assignment | function_call }
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -65,14 +65,16 @@ module Vm
|
|||||||
|
|
||||||
# currently aligned to 4 (ie padded with 0) and off course 0 at the end
|
# currently aligned to 4 (ie padded with 0) and off course 0 at the end
|
||||||
def initialize(str)
|
def initialize(str)
|
||||||
super()
|
super(str)
|
||||||
length = str.length
|
length = str.length
|
||||||
# rounding up to the next 4 (always adding one for zero pad)
|
# rounding up to the next 4 (always adding one for zero pad)
|
||||||
pad = ((length / 4 ) + 1 ) * 4 - length
|
pad = ((length / 4 ) + 1 ) * 4 - length
|
||||||
raise "#{pad} #{self}" unless pad >= 1
|
raise "#{pad} #{self}" unless pad >= 1
|
||||||
@string = str + "\x00" * pad
|
@string = str + "\x00" * pad
|
||||||
end
|
end
|
||||||
attr_reader :string
|
def string
|
||||||
|
@value
|
||||||
|
end
|
||||||
|
|
||||||
def load reg_num
|
def load reg_num
|
||||||
Machine.instance.string_load self , reg_num
|
Machine.instance.string_load self , reg_num
|
||||||
|
@ -10,7 +10,7 @@ module ParserHelper
|
|||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def setup
|
def setup
|
||||||
@parser = Parser::Composed.new
|
@parser = Parser::Crystal.new
|
||||||
@transform = Parser::Transform.new
|
@transform = Parser::Transform.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class TestRunner < MiniTest::Test
|
|||||||
|
|
||||||
def execute file
|
def execute file
|
||||||
string = File.read(file)
|
string = File.read(file)
|
||||||
parser = Parser::Composed.new
|
parser = Parser::Crystal.new
|
||||||
program = Vm::Program.new "Arm"
|
program = Vm::Program.new "Arm"
|
||||||
parts = string.split "SPLIT"
|
parts = string.split "SPLIT"
|
||||||
parts.each_with_index do |part,index|
|
parts.each_with_index do |part,index|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user