예제 #1
0
func (my *Parser) hDeclaration() {
	my.prepareDbgi()
	c := my.rd.tell()

	if c == '$' {
		my.wr.putcv('s', 't', 'a', 't', 'i', 'c', ' ')
		my.rd.fmove()
		c = my.rd.tell()
	}

	switch {
	case c == '(':
		if my.data.hasMain == false {
			my.data.hasMain = true
			my.wr.puts(syntax.FUNC_MAIN)
			my.skipUntil('{')
		} else {
			msg.Cerr(syntax.E_MULTIPLE_MAIN, msg.E_ERROR)
		}

	case isLetter(c):
		my.rd.memset()

		my.skipWhile(isLetter)
		my.skipWhile(isIndent)
		for my.rd.tell() == '*' {
			my.rd.fmove()
		}
		str := my.rd.slice()
		my.skipWhile(isIndent)

		if c = my.rd.tell(); isLetter(c) {
			my.wr.putcv('s', 't', 'r', 'u', 'c', 't', ' ')
			my.wr.puts(str)
			my.appendWhile(isLetter)
			my.hfAppendScalarInit()
		} else if c == '{' {
			my.wr.putcv('s', 't', 'r', 'u', 'c', 't', ' ')
			my.wr.puts(str)
		} else {
			msg.Cerr(syntax.E_INVALID_DECLARATION, msg.E_ERROR)
		}

		my.insertSpaceIf(isLetter(my.rd.tell()))

	default:
		if c != '-' {
			my.wr.putc('u')
		} else {
			my.rd.fmove()
		}

		my.wr.putc('i')

		my.appendWhile(isDigit)
		my.insertSpaceIf(my.rd.tell() != ' ')
		my.appendWhile(isLetter)
		my.hfAppendScalarInit()
	}
}
예제 #2
0
func (my *Parser) hConditional() {
	my.prepareDbgi()
	var c byte

	wbuf, wpos := my.wr.getData()
	my.wr.alloc(16)

	for c = my.rd.getc(); c != NULL && c != '{' && c != '\\'; c = my.rd.tell() {
		my.dive()
	}

	expr := my.wr.extract()
	my.wr.setData(wbuf, wpos)

	if c == '{' {
		if my.data.morphing == TERNARY {
			msg.Cerr("Nested ? expression is forbidden.", msg.E_ERROR)
		}

		my.wr.putcv('i', 'f', '(')
		my.wr.puts(expr)
		my.wr.putcv(')', ' ')
	} else if c == '\\' {
		morphBackup := my.data.morphing
		my.data.morphing = TERNARY

		my.wr.puts(expr)

		my.wr.putcv(' ', '?')
		my.insertSpaceIf(my.rd.fpeek() != ' ')

		for c = my.rd.getc(); c != NULL && c != ':'; c = my.rd.tell() {
			my.dive()
		}

		my.insertSpaceIf(my.rd.bpeek() != ' ')
		my.wr.putc(my.rd.tell())
		my.insertSpaceIf(my.rd.fpeek() != ' ')

		for c = my.rd.getc(); c != NULL && c != ';'; c = my.rd.tell() {
			my.dive()
		}

		my.data.morphing = morphBackup
	} else {
		msg.Cerr(syntax.E_INCOMPL_CONDITIONAL, msg.E_ERROR)
	}
}
예제 #3
0
func (my *Parser) appendComment() {
	if my.rd.fpeek() == '/' {
		my.appendSLComment()
	} else {
		my.prepareDbgi()
		my.wr.putcv('/', '*')
		my.rd.skip(2)

		my.appendMLComment()

		msg.Cerr(syntax.W_STYLE_ML_COMMENT, msg.E_WARNING)

		if my.rd.tell() != '*' {
			msg.Cerr(syntax.W_INCOMPL_ML_COMMENT, msg.E_WARNING)
		}
	}
}
예제 #4
0
func (my *Parser) appendMacro() {
	my.prepareDbgi()

	if my.lookBack() != '\n' {
		msg.Cerr(syntax.E_STRAIN_MACRO, msg.E_ERROR)
	}

	my.wr.putc(my.rd.getc())
	my.appendUntil(sys.NEWLINE)
	my.pushNewline()
}
예제 #5
0
func (my *Parser) hfAppendScalarInit() {
	my.prepareDbgi()
	my.skipWhile(isIndent)
	c := my.rd.tell()

	switch c {
	case '{':
		my.wr.putc('=')

	case '=':
		msg.Cerr(syntax.W_EQ_SIGN_IN_INIT, msg.E_WARNING)
		my.wr.putc(my.rd.getc())

	default:
	}
}
예제 #6
0
func (my *Parser) hTransition() {
	my.prepareDbgi()
	c := my.rd.tell()

	if c == ']' {
		my.wr.putcv('r', 'e', 't', 'u', 'r', 'n')
		my.insertSpaceIf(my.rd.fpeek() != ' ')
	} else {
		my.wr.putcv('g', 'o', 't', 'o', ' ')
		my.appendWhile(isLetter)

		if my.rd.tell() != ']' {
			msg.Cerr(syntax.E_BROKEN_TRANSITIONAL, msg.E_ERROR)
		}
	}

	my.rd.fmove()
}
예제 #7
0
func (my *Parser) hUnexpected() {
	my.prepareDbgi()
	msg.Cerr("Unexpected token found!", msg.E_ERROR)
}